<?php

namespace App\Http\Middleware;

use Closure;
use Cache;
use Auth;

class EntryGuardMiddleware
{
    /**
     * 个别页面访问需要安全密码校验
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if ($request->isMethod('get')) {
            if (!Cache::get(Auth::id() . '_guard')) {
                // 获取访问地址
                session(['url' => $request->path()]);
                return redirect('entryguard');
            }
        }
        return $next($request);
    }
}
